package com.liaogui.锁.sync;

import java.util.concurrent.TimeUnit;

/**
 * 非静态方法
 * @author liaogui
 * @date 2025/3/31 22:22
 */
public class Test01 {
    public static void main(String[] args) {
        Data data = new Data();
        new Thread(() -> {
            data.fun1();
        }, "A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        new Thread(() -> {
            data.fun2();
        }, "B").start();
    }
}

class Data {
    public synchronized void fun1() {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("1...");

    }

    public synchronized void fun2() {
        System.out.println("2...");
    }
}
